package cn.by.wms.javaweb;

import cn.by.wms.App;
import cn.hutool.core.date.StopWatch;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.RequestFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
//@WebFilter("/api/*")
@Slf4j
public class LogTimeFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        chain.doFilter(request,response);
        stopWatch.stop();
        String url = ((RequestFacade) request).getRequestURI().toString();
        String method = ((RequestFacade) request).getMethod().toString();
        log.debug("{},{}耗时:{}",url,method,stopWatch.getTotalTimeSeconds());

    }
}
